﻿
using System.Data.Common;
using Unity.Mathematics;
using UnityEngine;
using Event = Framework.Event.Event;

namespace Game.Input
{
    public class InputInfo
    {
        public Vector2 moveDir;
        public bool isMoving;


        public override string ToString()
        {
            return "isMoving:" + isMoving + " moveDir: " + moveDir;
        }
    }

    public abstract class InputBase: Event
    {
        public static class Event
        {
            public const string MOVE_DIR_CHG = "InputMoveDirChg";
        }

        public bool enable = false;
        
        private readonly InputInfo m_inputInfo = new InputInfo();
        
        public void Update()
        
        {
            
            if (!enable)
            {
                return;
            }
            CheckInputEvent();
        }

        protected abstract void CheckInputEvent();
        
        protected void MoveDirChg(float x, float y,bool isMoving)
        {
            m_inputInfo.isMoving = isMoving;
            m_inputInfo.moveDir.x = x;
            m_inputInfo.moveDir.y = y;
            m_inputInfo.moveDir.Normalize();
            this.Emit(InputBase.Event.MOVE_DIR_CHG, m_inputInfo);
        }
    }
}